package org.zsk.cs.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;
import org.zsk.cs.domain.po.Forum;
import org.zsk.cs.domain.vo.ForumVo;
import org.zsk.cs.response.ResultBody;
import org.zsk.cs.sendmail.MailService;
import org.zsk.cs.util.UserUtils;
import org.zsk.cs.util.common.enums.EmailSubject;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * <p>
 *     邮箱 controller
 * </p>
 *
 * @author zsk
 * @version 1.0
 * Created on 2020/4/19
 */
@RestController
@RequestMapping("/mail")
public class MailController {

    private final MailService mailService;

    @Autowired
    public MailController(MailService mailService) {
        this.mailService = mailService;
    }

    /**
     * 绑定邮箱
     * @param email 邮箱
     * @return
     * @throws Exception
     */
    @PutMapping("/bind")
    public ResultBody bind(@RequestParam String email,@RequestParam String emailVerifyCode) throws Exception {
        return ResultBody.success(mailService.bind(email,emailVerifyCode));
    }

    /**
     * 解绑邮箱
     * @param emailVerifyCode 验证码
     * @return
     * @throws Exception
     */
    @PutMapping("/unbind")
    public ResultBody unbind(@RequestParam String emailVerifyCode) throws Exception {
        return ResultBody.success(mailService.unBind(emailVerifyCode));
    }

    @PutMapping("/active")
    public ResultBody active(@RequestParam String emailVerifyCode) throws Exception {
        return ResultBody.success(mailService.active(emailVerifyCode));
    }

    @GetMapping("/emailvcodeForResetPass")
    public ResultBody emailvcodeForResetPass(@RequestParam int emailType,@RequestParam(required = false) String email) throws Exception {
        mailService.sendEmailVerifyCode(EmailSubject.getByValue(emailType),email);
        return ResultBody.success();
    }

    @GetMapping("/emailvcode")
    public ResultBody emailVerifyCode(@RequestParam int emailType,@RequestParam(required = false) String email) throws Exception {
        mailService.sendEmailVerifyCode(EmailSubject.getByValue(emailType),email);
        return ResultBody.success();
    }
}
